<!--
  Copyright 2019 Google LLC

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="../../bower_components/paper-button/paper-button.html">
<link rel="import" href="../../bower_components/paper-card/paper-card.html">
<link rel="import" href="../../bower_components/paper-styles/color.html">
<link rel="import" href="../../bower_components/paper-styles/typography.html">
<link rel="import" href="../common/if-else/if-else.html">

<dom-module id="oss-fuzz-home">
  <link rel="import" href="../../stylesheets/main.css" type="css">
  <link rel="import" href="../technology/technology.css" type="css">
  <template>
    <style include="iron-flex iron-flex-alignment">
      :host #welcome {
        width: 100%;
        margin: 0.6em 0;
      }

      .target {
        --paper-card-background-color: #f2f7fa;
        margin: 0.6em;
      }

      .project-links {
        margin: 0.6em;
      }

      :host h2 {
        @apply(--paper-font-headline);
      }
    </style>
    <paper-card id="welcome" heading="Welcome">
      <div class="card-content">
        <p>Welcome to ClusterFuzz, the fuzzing infrastructure behind OSS-Fuzz.
        Here you can look at crashes, statistics, and coverage information for
        your fuzzers. Below is an overview of your projects and their fuzzing
        configurations.</p>
      </div>
       <div class="card-actions">
         <a href="/testcases"><paper-button>All current crashes</paper-button></a>
         <template is="dom-if" if="[[info.is_internal_user]]">
           <a href="/fuzzer-stats/by-fuzzer/fuzzer/libFuzzer"><paper-button>All fuzzer stats</paper-button></a>
           <a href="/crash-stats"><paper-button>All crash stats</paper-button></a>
         </template>
         <a href="https://oss-fuzz-build-logs.storage.googleapis.com/index.html"><paper-button>Builds status</paper-button></a>
         <a href="https://github.com/google/oss-fuzz"><paper-button>Documentation</paper-button></a>
         <a href="https://github.com/google/oss-fuzz/issues/new"><paper-button>Report a bug</paper-button></a>
       </div>
    </paper-card>
    <template is="dom-repeat" items="[[info.projects]]" as="project">
      <h2>[[project.name]]</h2>
      <div class="project-links">
        <a href="/testcases?project=[[project.name]]&open=yes"><paper-button raised>Open crashes</paper-button></a>
        <a href="/crash-stats?project=[[project.name]]"><paper-button raised>Crash stats</paper-button></a>
        <a href="/coverage-report/job/[[project.coverage_job]]/latest"><paper-button raised>Total coverage</paper-button></a>
      </div>
      <div class="layout horizontal wrap">
        <template is="dom-repeat" items="[[project.jobs]]" as ="job">
          <paper-card class="target" heading="[[job.name]]">
            <div class="card-content">
              <p>Fuzzing engine: [[job.engine_display_name]]</p>
              <p>[[job.sanitizer_string]]</p>
            </div>
            <div class="card-actions">
             <template is="dom-if" if="{{job.has_stats}}">
               <if-else condition="[[job.single_target]]">
                  <a slot="t" href="/fuzzer-stats/by-day/fuzzer/[[job.single_target]]/job/[[job.name]]"><paper-button>Fuzzer stats/coverage</paper-button></a>
                  <a slot="f" href="/fuzzer-stats/by-fuzzer/fuzzer/[[job.engine_name]]/job/[[job.name]]"><paper-button>Fuzzer stats/coverage</paper-button></a>
               </if-else>
             </template>
            </div>
          </template>
        </paper-card>
      </div>
    </template>
  </template>
  <script>
    class OssFuzzHome extends Polymer.Element {
      static get is() { return 'oss-fuzz-home'; }
    }

    customElements.define(OssFuzzHome.is, OssFuzzHome);
  </script>
</dom-module>

